home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / doom / quake1.zip / LAVAGUN.ZIP / SRC / WEAPONS.QC < prev   
Text File  |  1996-08-09  |  26KB  |  1,271 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav");    // player shotgun
  17.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");    // super spikes
  21.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  25.     precache_sound ("weapons/lavagun.wav");    // super shotgun
  26.     precache_model ("progs/lavaball.mdl");    // super shotgun
  27. };
  28.  
  29. float() crandom =
  30. {
  31.     return 2*(random() - 0.5);
  32. };
  33.  
  34. /*
  35. ================
  36. W_FireAxe
  37. ================
  38. */
  39. void() W_FireAxe =
  40. {
  41.     local    vector    source;
  42.     local    vector    org;
  43.  
  44.     source = self.origin + '0 0 16';
  45.     traceline (source, source + v_forward*64, FALSE, self);
  46.     if (trace_fraction == 1.0)
  47.         return;
  48.     
  49.     org = trace_endpos - v_forward*4;
  50.  
  51.     if (trace_ent.takedamage)
  52.     {
  53.         trace_ent.axhitme = 1;
  54.         SpawnBlood (org, '0 0 0', 20);
  55.         T_Damage (trace_ent, self, self, 20);
  56.     }
  57.     else
  58.     {    // hit wall
  59.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  60.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  61.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  62.         WriteCoord (MSG_BROADCAST, org_x);
  63.         WriteCoord (MSG_BROADCAST, org_y);
  64.         WriteCoord (MSG_BROADCAST, org_z);
  65.     }
  66. };
  67.  
  68.  
  69. //============================================================================
  70.  
  71.  
  72. vector() wall_velocity =
  73. {
  74.     local vector    vel;
  75.     
  76.     vel = normalize (self.velocity);
  77.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  78.     vel = vel + 2*trace_plane_normal;
  79.     vel = vel * 200;
  80.     
  81.     return vel;
  82. };
  83.  
  84.  
  85. /*
  86. ================
  87. SpawnMeatSpray
  88. ================
  89. */
  90. void(vector org, vector vel) SpawnMeatSpray =
  91. {
  92.     local    entity missile, mpuff;
  93.     local    vector    org;
  94.  
  95.     missile = spawn ();
  96.     missile.owner = self;
  97.     missile.movetype = MOVETYPE_BOUNCE;
  98.     missile.solid = SOLID_NOT;
  99.  
  100.     makevectors (self.angles);
  101.  
  102.     missile.velocity = vel;
  103.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  104.  
  105.     missile.avelocity = '3000 1000 2000';
  106.     
  107. // set missile duration
  108.     missile.nextthink = time + 1;
  109.     missile.think = SUB_Remove;
  110.  
  111.     setmodel (missile, "progs/zom_gib.mdl");
  112.     setsize (missile, '0 0 0', '0 0 0');        
  113.     setorigin (missile, org);
  114. };
  115.  
  116. /*
  117. ================
  118. SpawnBlood
  119. ================
  120. */
  121. void(vector org, vector vel, float damage) SpawnBlood =
  122. {
  123.     particle (org, vel*0.1, 73, damage*2);
  124. };
  125.  
  126. /*
  127. ================
  128. spawn_touchblood
  129. ================
  130. */
  131. void(float damage) spawn_touchblood =
  132. {
  133.     local vector    vel;
  134.  
  135.     vel = wall_velocity () * 0.2;
  136.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  137. };
  138.  
  139.  
  140. /*
  141. ================
  142. SpawnChunk
  143. ================
  144. */
  145. void(vector org, vector vel) SpawnChunk =
  146. {
  147.     particle (org, vel*0.02, 0, 10);
  148. };
  149.  
  150. /*
  151. ==============================================================================
  152.  
  153. MULTI-DAMAGE
  154.  
  155. Collects multiple small damages into a single damage
  156.  
  157. ==============================================================================
  158. */
  159.  
  160. entity    multi_ent;
  161. float    multi_damage;
  162.  
  163. void() ClearMultiDamage =
  164. {
  165.     multi_ent = world;
  166.     multi_damage = 0;
  167. };
  168.  
  169. void() ApplyMultiDamage =
  170. {
  171.     if (!multi_ent)
  172.         return;
  173.     T_Damage (multi_ent, self, self, multi_damage);
  174. };
  175.  
  176. void(entity hit, float damage) AddMultiDamage =
  177. {
  178.     if (!hit)
  179.         return;
  180.     
  181.     if (hit != multi_ent)
  182.     {
  183.         ApplyMultiDamage ();
  184.         multi_damage = damage;
  185.         multi_ent = hit;
  186.     }
  187.     else
  188.         multi_damage = multi_damage + damage;
  189. };
  190.  
  191. /*
  192. ==============================================================================
  193.  
  194. BULLETS
  195.  
  196. ==============================================================================
  197. */
  198.  
  199. /*
  200. ================
  201. TraceAttack
  202. ================
  203. */
  204. void(float damage, vector dir) TraceAttack =
  205. {
  206.     local    vector    vel, org;
  207.     
  208.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  209.     vel = vel + 2*trace_plane_normal;
  210.     vel = vel * 200;
  211.  
  212.     org = trace_endpos - dir*4;
  213.  
  214.     if (trace_ent.takedamage)
  215.     {
  216.         SpawnBlood (org, vel*0.2, damage);
  217.         AddMultiDamage (trace_ent, damage);
  218.     }
  219.     else
  220.     {
  221.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  222.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  223.         WriteCoord (MSG_BROADCAST, org_x);
  224.         WriteCoord (MSG_BROADCAST, org_y);
  225.         WriteCoord (MSG_BROADCAST, org_z);
  226.     }
  227. };
  228.  
  229. /*
  230. ================
  231. FireBullets
  232.  
  233. Used by shotgun, super shotgun, and enemy soldier firing
  234. Go to the trouble of combining multiple pellets into a single damage call.
  235. ================
  236. */
  237. void(float shotcount, vector dir, vector spread) FireBullets =
  238. {
  239.     local    vector direction;
  240.     local    vector    src;
  241.     
  242.     makevectors(self.v_angle);
  243.  
  244.     src = self.origin + v_forward*10;
  245.     src_z = self.absmin_z + self.size_z * 0.7;
  246.  
  247.     ClearMultiDamage ();
  248.     while (shotcount > 0)
  249.     {
  250.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  251.  
  252.         traceline (src, src + direction*2048, FALSE, self);
  253.         if (trace_fraction != 1.0)
  254.             TraceAttack (4, direction);
  255.  
  256.         shotcount = shotcount - 1;
  257.     }
  258.     ApplyMultiDamage ();
  259. };
  260.  
  261. /*
  262. ================
  263. W_FireShotgun
  264. ================
  265. */
  266. void() W_FireShotgun =
  267. {
  268.     local vector dir;
  269.  
  270.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  271.  
  272.     self.punchangle_x = -2;
  273.     
  274.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  275.     dir = aim (self, 100000);
  276.     FireBullets (6, dir, '0.04 0.04 0');
  277. };
  278.  
  279.  
  280. /*
  281. ================
  282. W_FireSuperShotgun
  283. ================
  284. */
  285. void() W_FireSuperShotgun =
  286. {
  287.     local vector dir;
  288.  
  289.     if (self.currentammo == 1)
  290.     {
  291.         W_FireShotgun ();
  292.         return;
  293.     }
  294.         
  295.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  296.  
  297.     self.punchangle_x = -4;
  298.     
  299.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  300.     dir = aim (self, 100000);
  301.     FireBullets (14, dir, '0.14 0.08 0');
  302. };
  303.  
  304.  
  305. /*
  306. ==============================================================================
  307.  
  308. ROCKETS
  309.  
  310. ==============================================================================
  311. */
  312.  
  313. void()    s_explode1    =    [0,        s_explode2] {};
  314. void()    s_explode2    =    [1,        s_explode3] {};
  315. void()    s_explode3    =    [2,        s_explode4] {};
  316. void()    s_explode4    =    [3,        s_explode5] {};
  317. void()    s_explode5    =    [4,        s_explode6] {};
  318. void()    s_explode6    =    [5,        SUB_Remove] {};
  319.  
  320. void() BecomeExplosion =
  321. {
  322.     self.movetype = MOVETYPE_NONE;
  323.     self.velocity = '0 0 0';
  324.     self.touch = SUB_Null;
  325.     setmodel (self, "progs/s_explod.spr");
  326.     self.solid = SOLID_NOT;
  327.     s_explode1 ();
  328. };
  329.  
  330. void() T_MissileTouch =
  331. {
  332.     local float    damg;
  333.  
  334.     if (other == self.owner)
  335.         return;        // don't explode on owner
  336.  
  337.     if (pointcontents(self.origin) == CONTENT_SKY)
  338.     {
  339.         remove(self);
  340.         return;
  341.     }
  342.  
  343.     damg = 100 + random()*20;
  344.  
  345.     if (other.health)
  346.     {
  347.         if (other.classname == "monster_shambler")
  348.             damg = damg * 0.5;    // mostly immune
  349.         T_Damage (other, self, self.owner, damg );
  350.     }
  351.  
  352.     // don't do radius damage to the other, because all the damage
  353.     // was done in the impact
  354.     T_RadiusDamage (self, self.owner, 120, other);
  355.  
  356. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  357.     self.origin = self.origin - 8*normalize(self.velocity);
  358.  
  359.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  360.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  361.     WriteCoord (MSG_BROADCAST, self.origin_x);
  362.     WriteCoord (MSG_BROADCAST, self.origin_y);
  363.     WriteCoord (MSG_BROADCAST, self.origin_z);
  364.  
  365.     BecomeExplosion ();
  366. };
  367.  
  368. void() T_LavaTouch =
  369. {
  370.     local float    damg;
  371.  
  372.     if (other == self.owner)
  373.         return;        // don't explode on owner
  374.  
  375.     if (pointcontents(self.origin) == CONTENT_SKY)
  376.     {
  377.         remove(self);
  378.         return;
  379.     }
  380.  
  381.     damg = 32 + random()*8;
  382.  
  383.     if (other.health)
  384.     {
  385.         T_Damage (other, self, self.owner, damg );
  386.     }
  387.  
  388.     self.origin = self.origin - 8*normalize(self.velocity);
  389.  
  390.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  391.     WriteByte (MSG_BROADCAST, TE_LAVASPLASH);
  392.     WriteCoord (MSG_BROADCAST, self.origin_x);
  393.     WriteCoord (MSG_BROADCAST, self.origin_y);
  394.     WriteCoord (MSG_BROADCAST, self.origin_z);
  395.  
  396.         remove(self);
  397. };
  398.  
  399.  
  400.  
  401. /*
  402. ================
  403. W_FireRocket
  404. ================
  405. */
  406. void() W_FireRocket =
  407. {
  408.     local    entity missile, mpuff;
  409.     
  410.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  411.     
  412.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  413.  
  414.     self.punchangle_x = -2;
  415.  
  416.     missile = spawn ();
  417.     missile.owner = self;
  418.     missile.movetype = MOVETYPE_FLYMISSILE;
  419.     missile.solid = SOLID_BBOX;
  420.         
  421. // set missile speed    
  422.  
  423.     makevectors (self.v_angle);
  424.     missile.velocity = aim(self, 1000);
  425.     missile.velocity = missile.velocity * 1000;
  426.     missile.angles = vectoangles(missile.velocity);
  427.     
  428.     missile.touch = T_MissileTouch;
  429.     
  430. // set missile duration
  431.     missile.nextthink = time + 5;
  432.     missile.think = SUB_Remove;
  433.  
  434.     setmodel (missile, "progs/missile.mdl");
  435.     setsize (missile, '0 0 0', '0 0 0');        
  436.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  437. };
  438.  
  439. /*
  440. ===============================================================================
  441.  
  442. LIGHTNING
  443.  
  444. ===============================================================================
  445. */
  446.  
  447. /*
  448. =================
  449. LightningDamage
  450. =================
  451. */
  452. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  453. {
  454.     local entity        e1, e2;
  455.     local vector        f;
  456.     
  457.     f = p2 - p1;
  458.     normalize (f);
  459.     f_x = 0 - f_y;
  460.     f_y = f_x;
  461.     f_z = 0;
  462.     f = f*16;
  463.  
  464.     e1 = e2 = world;
  465.  
  466.     traceline (p1, p2, FALSE, self);
  467.     if (trace_ent.takedamage)
  468.     {
  469.         particle (trace_endpos, '0 0 100', 225, damage*4);
  470.         T_Damage (trace_ent, from, from, damage);
  471.         if (self.classname == "player")
  472.         {
  473.             if (other.classname == "player")
  474.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  475.         }
  476.     }
  477.     e1 = trace_ent;
  478.  
  479.     traceline (p1 + f, p2 + f, FALSE, self);
  480.     if (trace_ent != e1 && trace_ent.takedamage)
  481.     {
  482.         particle (trace_endpos, '0 0 100', 225, damage*4);
  483.         T_Damage (trace_ent, from, from, damage);
  484.     }
  485.     e2 = trace_ent;
  486.  
  487.     traceline (p1 - f, p2 - f, FALSE, self);
  488.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  489.     {
  490.         particle (trace_endpos, '0 0 100', 225, damage*4);
  491.         T_Damage (trace_ent, from, from, damage);
  492.     }
  493. };
  494.  
  495.  
  496. void() W_FireLightning =
  497. {
  498.     local    vector        org;
  499.  
  500.     if (self.ammo_cells < 1)
  501.     {
  502.         self.weapon = W_BestWeapon ();
  503.         W_SetCurrentAmmo ();
  504.         return;
  505.     }
  506.  
  507. // explode if under water
  508.     if (self.waterlevel > 1)
  509.     {
  510.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  511.         self.ammo_cells = 0;
  512.         W_SetCurrentAmmo ();
  513.         return;
  514.     }
  515.  
  516.     if (self.t_width < time)
  517.     {
  518.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  519.         self.t_width = time + 0.6;
  520.     }
  521.     self.punchangle_x = -2;
  522.  
  523.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  524.  
  525.     org = self.origin + '0 0 16';
  526.     
  527.     traceline (org, org + v_forward*600, TRUE, self);
  528.  
  529.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  530.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  531.     WriteEntity (MSG_BROADCAST, self);
  532.     WriteCoord (MSG_BROADCAST, org_x);
  533.     WriteCoord (MSG_BROADCAST, org_y);
  534.     WriteCoord (MSG_BROADCAST, org_z);
  535.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  536.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  537.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  538.  
  539.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  540. };
  541.  
  542.  
  543. //=============================================================================
  544.  
  545.  
  546. void() GrenadeExplode =
  547. {
  548.     T_RadiusDamage (self, self.owner, 120, world);
  549.  
  550.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  551.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  552.     WriteCoord (MSG_BROADCAST, self.origin_x);
  553.     WriteCoord (MSG_BROADCAST, self.origin_y);
  554.     WriteCoord (MSG_BROADCAST, self.origin_z);
  555.  
  556.     BecomeExplosion ();
  557. };
  558.  
  559. void() GrenadeTouch =
  560. {
  561.     if (other == self.owner)
  562.         return;        // don't explode on owner
  563.     if (other.takedamage == DAMAGE_AIM)
  564.     {
  565.         GrenadeExplode();
  566.         return;
  567.     }
  568.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  569.     if (self.velocity == '0 0 0')
  570.         self.avelocity = '0 0 0';
  571. };
  572.  
  573. /*
  574. ================
  575. W_FireGrenade
  576. ================
  577. */
  578. void() W_FireGrenade =
  579. {
  580.     local    entity missile, mpuff;
  581.     
  582.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  583.     
  584.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  585.  
  586.     self.punchangle_x = -2;
  587.  
  588.     missile = spawn ();
  589.     missile.owner = self;
  590.     missile.movetype = MOVETYPE_BOUNCE;
  591.     missile.solid = SOLID_BBOX;
  592.     missile.classname = "grenade";
  593.         
  594. // set missile speed    
  595.  
  596.     makevectors (self.v_angle);
  597.  
  598.     if (self.v_angle_x)
  599.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  600.     else
  601.     {
  602.         missile.velocity = aim(self, 10000);
  603.         missile.velocity = missile.velocity * 600;
  604.         missile.velocity_z = 200;
  605.     }
  606.  
  607.     missile.avelocity = '300 300 300';
  608.  
  609.     missile.angles = vectoangles(missile.velocity);
  610.     
  611.     missile.touch = GrenadeTouch;
  612.     
  613. // set missile duration
  614.     missile.nextthink = time + 2.5;
  615.     missile.think = GrenadeExplode;
  616.  
  617.     setmodel (missile, "progs/grenade.mdl");
  618.     setsize (missile, '0 0 0', '0 0 0');        
  619.     setorigin (missile, self.origin);
  620. };
  621.  
  622.  
  623. //=============================================================================
  624.  
  625. void() spike_touch;
  626. void() superspike_touch;
  627.  
  628.  
  629. /*
  630. ===============
  631. launch_spike
  632.  
  633. Used for both the player and the ogre
  634. ===============
  635. */
  636. void(vector org, vector dir) launch_spike =
  637. {
  638.     newmis = spawn ();
  639.     newmis.owner = self;
  640.     newmis.movetype = MOVETYPE_FLYMISSILE;
  641.     newmis.solid = SOLID_BBOX;
  642.  
  643.     newmis.angles = vectoangles(dir);
  644.  
  645.     newmis.touch = spike_touch;
  646.     newmis.classname = "spike";
  647.     newmis.think = SUB_Remove;
  648.     newmis.nextthink = time + 6;
  649.     setmodel (newmis, "progs/spike.mdl");
  650.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);
  651.     setorigin (newmis, org);
  652.  
  653.     newmis.velocity = dir * 1000;
  654. };
  655.  
  656. void() W_FireSuperSpikes =
  657. {
  658.     local    entity missile, mpuff;
  659.  
  660.     if (self.ammo_cells < 1) 
  661.         {
  662.         self.weapon = W_BestWeapon ();
  663.         W_SetCurrentAmmo ();
  664.         return;
  665.         }
  666.         self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  667.     sound (self, CHAN_WEAPON, "weapons/lavagun.wav", 1, ATTN_NORM);
  668.  
  669.     self.punchangle_x = -2;
  670.  
  671.     missile = spawn ();
  672.     missile.owner = self;
  673.     missile.movetype = MOVETYPE_FLYMISSILE;
  674.     missile.solid = SOLID_BBOX;
  675.  
  676. // set missile speed
  677.  
  678.     makevectors (self.v_angle);
  679.     missile.velocity = aim(self, 1000);
  680.     missile.velocity = missile.velocity * 1000;
  681.     missile.angles = vectoangles(missile.velocity);
  682.  
  683.     missile.touch = T_LavaTouch;
  684.  
  685.     setmodel (missile, "progs/lavaball.mdl");
  686.     setsize (missile, '0 0 0', '0 0 0');
  687.     setorigin (missile, self.origin + v_forward*8 + '0 0 8');
  688. };
  689.  
  690. void(float ox) W_FireSpikes =
  691. {
  692.     local vector    dir;
  693.     local entity    old;
  694.  
  695.     makevectors (self.v_angle);
  696.  
  697.     if (self.ammo_cells >= 1 && self.weapon == IT_SUPER_NAILGUN)
  698.     {
  699.         W_FireSuperSpikes ();
  700.         return;
  701.     }
  702.  
  703.     if (self.ammo_nails < 1)
  704.     {
  705.         self.weapon = W_BestWeapon ();
  706.         W_SetCurrentAmmo ();
  707.         return;
  708.     }
  709.  
  710.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  711.     self.attack_finished = time + 0.2;
  712.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  713.     dir = aim (self, 1000);
  714.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  715.  
  716.     self.punchangle_x = -2;
  717. };
  718.  
  719.  
  720.  
  721. .float hit_z;
  722. void() spike_touch =
  723. {
  724. local float rand;
  725.     if (other == self.owner)
  726.         return;
  727.  
  728.     if (other.solid == SOLID_TRIGGER)
  729.         return;    // trigger field, do nothing
  730.  
  731.     if (pointcontents(self.origin) == CONTENT_SKY)
  732.     {
  733.         remove(self);
  734.         return;
  735.     }
  736.     
  737. // hit something that bleeds
  738.     if (other.takedamage)
  739.     {
  740.         spawn_touchblood (9);
  741.         T_Damage (other, self, self.owner, 9);
  742.     }
  743.     else
  744.     {
  745.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  746.         
  747.         if (self.classname == "wizspike")
  748.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  749.         else if (self.classname == "knightspike")
  750.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  751.         else
  752.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  753.         WriteCoord (MSG_BROADCAST, self.origin_x);
  754.         WriteCoord (MSG_BROADCAST, self.origin_y);
  755.         WriteCoord (MSG_BROADCAST, self.origin_z);
  756.     }
  757.  
  758.     remove(self);
  759.  
  760. };
  761.  
  762. void() superspike_touch =
  763. {
  764. local float rand;
  765.     if (other == self.owner)
  766.         return;
  767.  
  768.     if (other.solid == SOLID_TRIGGER)
  769.         return;    // trigger field, do nothing
  770.  
  771.     if (pointcontents(self.origin) == CONTENT_SKY)
  772.     {
  773.         remove(self);
  774.         return;
  775.     }
  776.     
  777. // hit something that bleeds
  778.     if (other.takedamage)
  779.     {
  780.         spawn_touchblood (18);
  781.         T_Damage (other, self, self.owner, 18);
  782.     }
  783.     else
  784.     {
  785.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  786.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  787.         WriteCoord (MSG_BROADCAST, self.origin_x);
  788.         WriteCoord (MSG_BROADCAST, self.origin_y);
  789.         WriteCoord (MSG_BROADCAST, self.origin_z);
  790.     }
  791.  
  792.     remove(self);
  793.  
  794. };
  795.  
  796.  
  797. /*
  798. ===============================================================================
  799.  
  800. PLAYER WEAPON USE
  801.  
  802. ===============================================================================
  803. */
  804.  
  805. void() W_SetCurrentAmmo =
  806. {
  807.     player_run ();        // get out of any weapon firing states
  808.  
  809.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  810.     
  811.     if (self.weapon == IT_AXE)
  812.     {
  813.         self.currentammo = 0;
  814.         self.weaponmodel = "progs/v_axe.mdl";
  815.         self.weaponframe = 0;
  816.     }
  817.     else if (self.weapon == IT_SHOTGUN)
  818.     {
  819.         self.currentammo = self.ammo_shells;
  820.         self.weaponmodel = "progs/v_shot.mdl";
  821.         self.weaponframe = 0;
  822.         self.items = self.items | IT_SHELLS;
  823.     }
  824.     else if (self.weapon == IT_SUPER_SHOTGUN)
  825.     {
  826.         self.currentammo = self.ammo_shells;
  827.         self.weaponmodel = "progs/v_shot2.mdl";
  828.         self.weaponframe = 0;
  829.         self.items = self.items | IT_SHELLS;
  830.     }
  831.     else if (self.weapon == IT_NAILGUN)
  832.     {
  833.         self.currentammo = self.ammo_nails;
  834.         self.weaponmodel = "progs/v_nail.mdl";
  835.         self.weaponframe = 0;
  836.         self.items = self.items | IT_NAILS;
  837.     }
  838.     else if (self.weapon == IT_SUPER_NAILGUN)
  839.     {
  840.         self.currentammo = self.ammo_cells;
  841.         self.weaponmodel = "progs/v_nail2.mdl";
  842.         self.weaponframe = 0;
  843.         self.items = self.items | IT_CELLS;
  844.     }
  845.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  846.     {
  847.         self.currentammo = self.ammo_rockets;
  848.         self.weaponmodel = "progs/v_rock.mdl";
  849.         self.weaponframe = 0;
  850.         self.items = self.items | IT_ROCKETS;
  851.     }
  852.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  853.     {
  854.         self.currentammo = self.ammo_rockets;
  855.         self.weaponmodel = "progs/v_rock2.mdl";
  856.         self.weaponframe = 0;
  857.         self.items = self.items | IT_ROCKETS;
  858.     }
  859.     else if (self.weapon == IT_LIGHTNING)
  860.     {
  861.         self.currentammo = self.ammo_cells;
  862.         self.weaponmodel = "progs/v_light.mdl";
  863.         self.weaponframe = 0;
  864.         self.items = self.items | IT_CELLS;
  865.     }
  866.     else
  867.     {
  868.         self.currentammo = 0;
  869.         self.weaponmodel = "";
  870.         self.weaponframe = 0;
  871.     }
  872. };
  873.  
  874. float() W_BestWeapon =
  875. {
  876.     local    float    it;
  877.     
  878.     it = self.items;
  879.  
  880.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  881.         return IT_LIGHTNING;
  882.     else if(self.ammo_cells >= 1 && (it & IT_SUPER_NAILGUN) )
  883.         return IT_SUPER_NAILGUN;
  884.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  885.         return IT_SUPER_SHOTGUN;
  886.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  887.         return IT_NAILGUN;
  888.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  889.         return IT_SHOTGUN;
  890.     else if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  891.         return IT_ROCKET_LAUNCHER;
  892.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  893.         return IT_GRENADE_LAUNCHER;
  894.  
  895.  
  896.  
  897.     return IT_AXE;
  898. };
  899.  
  900. float() W_CheckNoAmmo =
  901. {
  902.     if (self.currentammo > 0)
  903.         return TRUE;
  904.  
  905.     if (self.weapon == IT_AXE)
  906.         return TRUE;
  907.     
  908.     self.weapon = W_BestWeapon ();
  909.  
  910.     W_SetCurrentAmmo ();
  911.     
  912. // drop the weapon down
  913.     return FALSE;
  914. };
  915.  
  916. /*
  917. ============
  918. W_Attack
  919.  
  920. An attack impulse can be triggered now
  921. ============
  922. */
  923. void()    player_axe1;
  924. void()    player_axeb1;
  925. void()    player_axec1;
  926. void()    player_axed1;
  927. void()    player_shot1;
  928. void()    player_nail1;
  929. void()    player_light1;
  930. void()    player_rocket1;
  931.  
  932. void() W_Attack =
  933. {
  934.     local    float    r;
  935.  
  936.     if (!W_CheckNoAmmo ())
  937.         return;
  938.  
  939.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  940.     self.show_hostile = time + 1;    // wake monsters up
  941.  
  942.     if (self.weapon == IT_AXE)
  943.     {
  944.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  945.         r = random();
  946.         if (r < 0.25)
  947.             player_axe1 ();
  948.         else if (r<0.5)
  949.             player_axeb1 ();
  950.         else if (r<0.75)
  951.             player_axec1 ();
  952.         else
  953.             player_axed1 ();
  954.         self.attack_finished = time + 0.5;
  955.     }
  956.     else if (self.weapon == IT_SHOTGUN)
  957.     {
  958.         player_shot1 ();
  959.         W_FireShotgun ();
  960.         self.attack_finished = time + 0.5;
  961.     }
  962.     else if (self.weapon == IT_SUPER_SHOTGUN)
  963.     {
  964.         player_shot1 ();
  965.         W_FireSuperShotgun ();
  966.         self.attack_finished = time + 0.7;
  967.     }
  968.     else if (self.weapon == IT_NAILGUN)
  969.     {
  970.         player_nail1 ();
  971.     }
  972.     else if (self.weapon == IT_SUPER_NAILGUN)
  973.     {
  974.         player_nail1 ();
  975.     }
  976.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  977.     {
  978.         player_rocket1();
  979.         W_FireGrenade();
  980.         self.attack_finished = time + 0.6;
  981.     }
  982.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  983.     {
  984.         player_rocket1();
  985.         W_FireRocket();
  986.         self.attack_finished = time + 0.8;
  987.     }
  988.     else if (self.weapon == IT_LIGHTNING)
  989.     {
  990.         player_light1();
  991.         self.attack_finished = time + 0.1;
  992.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  993.     }
  994. };
  995.  
  996. /*
  997. ============
  998. W_ChangeWeapon
  999.  
  1000. ============
  1001. */
  1002. void() W_ChangeWeapon =
  1003. {
  1004.     local    float    it, am, fl;
  1005.     
  1006.     it = self.items;
  1007.     am = 0;
  1008.     
  1009.     if (self.impulse == 1)
  1010.     {
  1011.         fl = IT_AXE;
  1012.     }
  1013.     else if (self.impulse == 2)
  1014.     {
  1015.         fl = IT_SHOTGUN;
  1016.         if (self.ammo_shells < 1)
  1017.             am = 1;
  1018.     }
  1019.     else if (self.impulse == 3)
  1020.     {
  1021.         fl = IT_SUPER_SHOTGUN;
  1022.         if (self.ammo_shells < 2)
  1023.             am = 1;
  1024.     }        
  1025.     else if (self.impulse == 4)
  1026.     {
  1027.         fl = IT_NAILGUN;
  1028.         if (self.ammo_nails < 1)
  1029.             am = 1;
  1030.     }
  1031.     else if (self.impulse == 5)
  1032.     {
  1033.         fl = IT_SUPER_NAILGUN;
  1034.         if (self.ammo_cells < 1)
  1035.             am = 1;
  1036.     }
  1037.     else if (self.impulse == 6)
  1038.     {
  1039.         fl = IT_GRENADE_LAUNCHER;
  1040.         if (self.ammo_rockets < 1)
  1041.             am = 1;
  1042.     }
  1043.     else if (self.impulse == 7)
  1044.     {
  1045.         fl = IT_ROCKET_LAUNCHER;
  1046.         if (self.ammo_rockets < 1)
  1047.             am = 1;
  1048.     }
  1049.     else if (self.impulse == 8)
  1050.     {
  1051.         fl = IT_LIGHTNING;
  1052.         if (self.ammo_cells < 1)
  1053.             am = 1;
  1054.     }
  1055.  
  1056.     self.impulse = 0;
  1057.     
  1058.     if (!(self.items & fl))
  1059.     {    // don't have the weapon or the ammo
  1060.         sprint (self, "no weapon.\n");
  1061.         return;
  1062.     }
  1063.     
  1064.     if (am)
  1065.     {    // don't have the ammo
  1066.         sprint (self, "not enough ammo.\n");
  1067.         return;
  1068.     }
  1069.  
  1070. //
  1071. // set weapon, set ammo
  1072. //
  1073.     self.weapon = fl;        
  1074.     W_SetCurrentAmmo ();
  1075. };
  1076.  
  1077. /*
  1078. ============
  1079. CheatCommand
  1080. ============
  1081. */
  1082. void() CheatCommand =
  1083. {
  1084.     if (deathmatch || coop)
  1085.         return;
  1086.  
  1087.     self.ammo_rockets = 100;
  1088.     self.ammo_nails = 200;
  1089.     self.ammo_shells = 100;
  1090.     self.items = self.items | 
  1091.         IT_AXE |
  1092.         IT_SHOTGUN |
  1093.         IT_SUPER_SHOTGUN |
  1094.         IT_NAILGUN |
  1095.         IT_SUPER_NAILGUN |
  1096.         IT_GRENADE_LAUNCHER |
  1097.         IT_ROCKET_LAUNCHER |
  1098.         IT_KEY1 | IT_KEY2;
  1099.  
  1100.     self.ammo_cells = 100;
  1101.     self.items = self.items | IT_LIGHTNING;
  1102.  
  1103.     self.weapon = IT_ROCKET_LAUNCHER;
  1104.     self.impulse = 0;
  1105.     W_SetCurrentAmmo ();
  1106. };
  1107.  
  1108. /*
  1109. ============
  1110. CycleWeaponCommand
  1111.  
  1112. Go to the next weapon with ammo
  1113. ============
  1114. */
  1115. void() CycleWeaponCommand =
  1116. {
  1117.     local    float    it, am;
  1118.     
  1119.     it = self.items;
  1120.     self.impulse = 0;
  1121.     
  1122.     while (1)
  1123.     {
  1124.         am = 0;
  1125.  
  1126.         if (self.weapon == IT_LIGHTNING)
  1127.         {
  1128.             self.weapon = IT_AXE;
  1129.         }
  1130.         else if (self.weapon == IT_AXE)
  1131.         {
  1132.             self.weapon = IT_SHOTGUN;
  1133.             if (self.ammo_shells < 1)
  1134.                 am = 1;
  1135.         }
  1136.         else if (self.weapon == IT_SHOTGUN)
  1137.         {
  1138.             self.weapon = IT_SUPER_SHOTGUN;
  1139.             if (self.ammo_shells < 2)
  1140.                 am = 1;
  1141.         }        
  1142.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1143.         {
  1144.             self.weapon = IT_NAILGUN;
  1145.             if (self.ammo_nails < 1)
  1146.                 am = 1;
  1147.         }
  1148.         else if (self.weapon == IT_NAILGUN)
  1149.         {
  1150.             self.weapon = IT_SUPER_NAILGUN;
  1151.             if (self.ammo_cells < 1)
  1152.                 am = 1;
  1153.         }
  1154.         else if (self.weapon == IT_SUPER_NAILGUN)
  1155.         {
  1156.             self.weapon = IT_GRENADE_LAUNCHER;
  1157.             if (self.ammo_rockets < 1)
  1158.                 am = 1;
  1159.         }
  1160.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1161.         {
  1162.             self.weapon = IT_ROCKET_LAUNCHER;
  1163.             if (self.ammo_rockets < 1)
  1164.                 am = 1;
  1165.         }
  1166.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1167.         {
  1168.             self.weapon = IT_LIGHTNING;
  1169.             if (self.ammo_cells < 1)
  1170.                 am = 1;
  1171.         }
  1172.     
  1173.         if ( (self.items & self.weapon) && am == 0)
  1174.         {
  1175.             W_SetCurrentAmmo ();
  1176.             return;
  1177.         }
  1178.     }
  1179.  
  1180. };
  1181.  
  1182. /*
  1183. ============
  1184. ServerflagsCommand
  1185.  
  1186. Just for development
  1187. ============
  1188. */
  1189. void() ServerflagsCommand =
  1190. {
  1191.     serverflags = serverflags * 2 + 1;
  1192. };
  1193.  
  1194. void() QuadCheat =
  1195. {
  1196.     if (deathmatch || coop)
  1197.         return;
  1198.     self.super_time = 1;
  1199.     self.super_damage_finished = time + 30;
  1200.     self.items = self.items | IT_QUAD;
  1201.     dprint ("quad cheat\n");
  1202. };
  1203.  
  1204. /*
  1205. ============
  1206. ImpulseCommands
  1207.  
  1208. ============
  1209. */
  1210. void() ImpulseCommands =
  1211. {
  1212.     if (self.impulse >= 1 && self.impulse <= 8)
  1213.         W_ChangeWeapon ();
  1214.  
  1215.     if (self.impulse == 9)
  1216.         CheatCommand ();
  1217.     if (self.impulse == 10)
  1218.         CycleWeaponCommand ();
  1219.     if (self.impulse == 11)
  1220.         ServerflagsCommand ();
  1221.  
  1222.     if (self.impulse == 255)
  1223.         QuadCheat ();
  1224.         
  1225.     self.impulse = 0;
  1226. };
  1227.  
  1228. /*
  1229. ============
  1230. W_WeaponFrame
  1231.  
  1232. Called every frame so impulse events can be handled as well as possible
  1233. ============
  1234. */
  1235. void() W_WeaponFrame =
  1236. {
  1237.     if (time < self.attack_finished)
  1238.         return;
  1239.  
  1240.     ImpulseCommands ();
  1241.     
  1242. // check for attack
  1243.     if (self.button0)
  1244.     {
  1245.         SuperDamageSound ();
  1246.         W_Attack ();
  1247.     }
  1248. };
  1249.  
  1250. /*
  1251. ========
  1252. SuperDamageSound
  1253.  
  1254. Plays sound if needed
  1255. ========
  1256. */
  1257. void() SuperDamageSound =
  1258. {
  1259.     if (self.super_damage_finished > time)
  1260.     {
  1261.         if (self.super_sound < time)
  1262.         {
  1263.             self.super_sound = time + 1;
  1264.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1265.         }
  1266.     }
  1267.     return;
  1268. };
  1269.  
  1270.  
  1271.